#include "teststdafx.h"
#include "stdafx.h"
#include <gtest/gtest.h>

#include "Business/ArbitrageLegs.h"
#include "Business/Bollinger.h"

class BandTest : public testing::Test
{
protected:

	virtual void SetUp()
	{
	}

	virtual void TearDown()
	{

	}
};

TEST_F(BandTest, BearishCanOpenTest)
{
	double bearishOpen = 90;
	double bearishOffset = 120;
	double bearishStop = 60;
	Band bearishBand(bearishOpen, bearishOffset,bearishStop);

	EXPECT_EQ(true,bearishBand.CanOpen(80,75));
	EXPECT_EQ(true,bearishBand.CanOpen(90,75));
	EXPECT_EQ(false,bearishBand.CanOpen(80,85));
	EXPECT_EQ(false,bearishBand.CanOpen(100,80));
	EXPECT_EQ(false,bearishBand.CanOpen(80,55));
}

TEST_F(BandTest, BearishCanOffsetTest)
{
	double bearishOpen = 90;
	double bearishOffset = 120;
	double bearishStop = 60;
	Band bearishBand(bearishOpen, bearishOffset,bearishStop);

	EXPECT_EQ(true,bearishBand.CanOffset(130));
	EXPECT_EQ(true,bearishBand.CanOffset(120));
	EXPECT_EQ(false,bearishBand.CanOffset(110));
}

TEST_F(BandTest, BearishCanStopTest)
{
	double bearishOpen = 90;
	double bearishOffset = 120;
	double bearishStop = 60;
	Band bearishBand(bearishOpen, bearishOffset,bearishStop);

	EXPECT_EQ(false,bearishBand.CanStop(70));
	EXPECT_EQ(true,bearishBand.CanStop(60));
	EXPECT_EQ(true,bearishBand.CanStop(55));
}

TEST_F(BandTest, BullishCanOpenTest)
{
	double bullishOpen = 90;
	double bullishOffset = 60;
	double bullishStop = 120;
	Band bullishBand(bullishOpen, bullishOffset,bullishStop);

	EXPECT_EQ(true,bullishBand.CanOpen(90,100));
	EXPECT_EQ(true,bullishBand.CanOpen(100,110));
	EXPECT_EQ(true,bullishBand.CanOpen(100,115));
	EXPECT_EQ(false,bullishBand.CanOpen(100,95));
	EXPECT_EQ(false,bullishBand.CanOpen(100,130));
	EXPECT_EQ(false,bullishBand.CanOpen(80,70));
}

TEST_F(BandTest, BullishCanOffsetTest)
{
	double bullishOpen = 90;
	double bullishOffset = 60;
	double bullishStop = 120;
	Band bullishBand(bullishOpen, bullishOffset,bullishStop);

	EXPECT_EQ(true,bullishBand.CanOffset(50));
	EXPECT_EQ(true,bullishBand.CanOffset(60));
	EXPECT_EQ(false,bullishBand.CanOffset(70));
}

TEST_F(BandTest, BullishCanStopTest)
{
	double bullishOpen = 90;
	double bullishOffset = 60;
	double bullishStop = 120;
	Band bullishBand(bullishOpen, bullishOffset,bullishStop);

	EXPECT_EQ(false,bullishBand.CanStop(110));
	EXPECT_EQ(true,bullishBand.CanStop(120));
	EXPECT_EQ(true,bullishBand.CanStop(130));
}

TEST_F(BandTest,IsSameTypeTest)
{
	double bullishOpen = 90;
	double bullishOffset = 60;
	double bullishStop = 120;
	Band bullishBand(bullishOpen, bullishOffset,bullishStop);

	double bearishOpen = 90;
	double bearishOffset = 120;
	double bearishStop = 60;
	Band bearishBand(bearishOpen, bearishOffset,bearishStop);

	double bearishOpen2 = 80;
	double bearishOffset2 = 120;
	double bearishStop2 = 60;
	Band bearishBand2(bearishOpen, bearishOffset,bearishStop);

	EXPECT_EQ(false,bearishBand.IsSameType(bullishBand));
	EXPECT_EQ(true,bearishBand.IsSameType(bearishBand2));
}

TEST_F(BandTest,UpdateByBollingerTest)
{
	double bullishOpen = 90;
	double bullishOffset = 60;
	double bullishStop = 120;
	Band bullishBand(bullishOpen, bullishOffset,bullishStop);

	double bearishOpen = 90;
	double bearishOffset = 120;
	double bearishStop = 60;
	Band bearishBand(bearishOpen, bearishOffset,bearishStop);

	Bollinger bollinger(100,80);

	bullishBand.UpdateByBollinger(bollinger);
	EXPECT_DOUBLE_EQ(MORE_UPPER,bullishBand.GetStop());
	EXPECT_DOUBLE_EQ(bollinger.GetUpper(),bullishBand.GetOpen());
	EXPECT_DOUBLE_EQ(bollinger.GetLower(),bullishBand.GetOffset());

	bearishBand.UpdateByBollinger(bollinger);
	EXPECT_DOUBLE_EQ(MORE_LOWER,bearishBand.GetStop());
	EXPECT_DOUBLE_EQ(bollinger.GetLower(),bearishBand.GetOpen());
	EXPECT_DOUBLE_EQ(bollinger.GetUpper(),bearishBand.GetOffset());
}